package com.hmall.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.doc.ItemDoc;
import com.hmall.dto.RequestParams;
import com.hmall.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-06-21 11:34
 */
@Slf4j
@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService searchService;

    /**
     * 自动补全
     *
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(String key) {
        return searchService.suggestion(key);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> getfilter(@RequestBody RequestParams requestParams){
        log.info("过滤项聚合:{}",requestParams);
        return  searchService.getfilter(requestParams);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams requestParams){
        return searchService.list(requestParams);
    }



}
